% # variable:
% # book, ebook, target_uuid, max_level

% bookuuid = ebook.get('uuid')

%def get_ezpath(ebook, target_uuid):
    % # 產生正序排列的，由enote構成的 ez 路徑 
    %path_uuids = [ebook]
    %enote = ebook
    %while True:
        %if enote.get('uuid') == target_uuid:
            %return path_uuids
        %end
        %for esub in enote.iterfind('./note'):
            %if esub.find('.//note[@uuid="{}"]'.format(target_uuid)) is not None or esub.get('uuid') == target_uuid:
                %enote = esub
                %path_uuids.append(esub)
                %break
            %end
        %end
    %end
%end

%enotes = get_ezpath(ebook, target_uuid)
%enotes.reverse() # 反轉排序

<ul class="menuroot">
    %for enote in enotes:
        %include nav_item book = book, eroot = enote, bookuuid = bookuuid, target_uuid = target_uuid, max_level = max_level, trace_path_enable = True
    %end
</ul>
